//
//  URLViewController.m
//  Bigeyes
//
//  Created by 红沙尘 on 17/6/15.
//  Copyright © 2017年 uShareit. All rights reserved.
//

#import "URLViewController.h"
#import "SQLITE.h"
@interface URLViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    __weak IBOutlet UITableView *myTableView;
    NSArray *urlArray;
}
@end

@implementation URLViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.    
    
    urlArray = [[SQLITE standardSqlite] selectDistinctWithKey:@"url" table:@"log"];
    
    myTableView.rowHeight = UITableViewAutomaticDimension;
    myTableView.estimatedRowHeight = 40;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return urlArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"URLCell"];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:0 reuseIdentifier:@"URLCell"];
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont systemFontOfSize:14];
    }
    
    cell.textLabel.text = urlArray[indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if ([self.urlDelegate respondsToSelector:@selector(didSelectedWithKey:url:)]) {
        [self.urlDelegate didSelectedWithKey:@"url" url:urlArray[indexPath.row]];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
